using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Styling;
using LuckyFish.ToDo.Data.Model;
using LuckyFish.ToDo.ViewModels;

namespace LuckyFish.ToDo.Views;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void SelectionChanged(object? sender, SelectionChangedEventArgs e)
    {
        if(DataContext is not MainWindowViewModel model)return;
        if(sender is not ListBox box)return;
        if(box.SelectedItem is not ToDoGroupModel group)return;
        model.ToGroupView(group);
    }

    private void TextTapped(object? sender, RoutedEventArgs e)
    {
        if(DataContext is not MainWindowViewModel model)return;
        if(sender is not Control control)return;
        if(control.DataContext is not ToDoGroupModel group)return;
        model.ToGroupView(group);
    }

    private void ThemeTapped(object? sender, TappedEventArgs e)
    {
        if (Application.Current == null) return;
        if (Application.Current.ActualThemeVariant == ThemeVariant.Light)
        {
            Application.Current.RequestedThemeVariant = ThemeVariant.Dark;
            SukiUI.ColorTheme.LoadDarkTheme(Application.Current);
            return;
        }

        if (Application.Current.ActualThemeVariant != ThemeVariant.Dark) return;
        Application.Current.RequestedThemeVariant = ThemeVariant.Light;
        SukiUI.ColorTheme.LoadLightTheme(Application.Current);
    }
}